<!DOCTYPE html>
<html>
<head>
  <meta charset="utf-8">
  
  <title>用django创建一个项目 | sunJsona的个人博客</title>

  <!-- keywords -->
  

  <meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1">
  <meta name="description" content="首先你得安装好python和django，然后配置好环境变量，安装python就不说了，从配置环境变量开始 1.配置环境变量在我的电脑处点击右键，或者打开 控制面板\系统和安全\系统 -&amp;gt; 左边导航栏的“高级系统设置”-&amp;gt;环境变量 –&amp;gt;然后你会看到下面这个界面 -&amp;gt; 点击这个path，然后点编辑 然后找到C:\Python27文件夹，将这个文件夹添加进去。 2.安装djan">
<meta property="og:type" content="article">
<meta property="og:title" content="用django创建一个项目">
<meta property="og:url" content="https://xiaochangzai.github.io/2020/07/07/用django创建一个项目/index.html">
<meta property="og:site_name" content="sunJsona的个人博客">
<meta property="og:description" content="首先你得安装好python和django，然后配置好环境变量，安装python就不说了，从配置环境变量开始 1.配置环境变量在我的电脑处点击右键，或者打开 控制面板\系统和安全\系统 -&amp;gt; 左边导航栏的“高级系统设置”-&amp;gt;环境变量 –&amp;gt;然后你会看到下面这个界面 -&amp;gt; 点击这个path，然后点编辑 然后找到C:\Python27文件夹，将这个文件夹添加进去。 2.安装djan">
<meta property="og:locale" content="Simple Chinese">
<meta property="og:image" content="https://sunchang.oss-cn-beijing.aliyuncs.com/image/828578-20170103195539128-1894247265.png">
<meta property="og:image" content="https://sunchang.oss-cn-beijing.aliyuncs.com/image/828578-20170103195951191-1293610516.png">
<meta property="og:image" content="https://sunchang.oss-cn-beijing.aliyuncs.com/image/828578-20170103200123878-1846022323.png">
<meta property="og:image" content="https://sunchang.oss-cn-beijing.aliyuncs.com/image/828578-20170103200738237-1012230503.png">
<meta property="og:image" content="https://sunchang.oss-cn-beijing.aliyuncs.com/image/828578-20170103200951722-394835961.png">
<meta property="og:image" content="https://sunchang.oss-cn-beijing.aliyuncs.com/image/828578-20170103201030722-218731608.png">
<meta property="og:image" content="https://sunchang.oss-cn-beijing.aliyuncs.com/image/828578-20170103201118253-933553388.png">
<meta property="og:image" content="https://sunchang.oss-cn-beijing.aliyuncs.com/image/828578-20170103202329550-1021831256.png">
<meta property="og:image" content="https://sunchang.oss-cn-beijing.aliyuncs.com/image/828578-20170103202532987-734281570.png">
<meta property="og:image" content="https://sunchang.oss-cn-beijing.aliyuncs.com/image/828578-20170103202638644-219210958.png">
<meta property="og:image" content="https://sunchang.oss-cn-beijing.aliyuncs.com/image/828578-20170103203359566-894259538.png">
<meta property="og:image" content="https://sunchang.oss-cn-beijing.aliyuncs.com/image/828578-20170103203233878-325335233.png">
<meta property="og:image" content="https://sunchang.oss-cn-beijing.aliyuncs.com/image/828578-20170103203550237-1673257793.png">
<meta property="og:image" content="https://sunchang.oss-cn-beijing.aliyuncs.com/image/828578-20170103203725644-2085813319.png">
<meta property="og:updated_time" content="2020-07-07T05:00:13.000Z">
<meta name="twitter:card" content="summary">
<meta name="twitter:title" content="用django创建一个项目">
<meta name="twitter:description" content="首先你得安装好python和django，然后配置好环境变量，安装python就不说了，从配置环境变量开始 1.配置环境变量在我的电脑处点击右键，或者打开 控制面板\系统和安全\系统 -&amp;gt; 左边导航栏的“高级系统设置”-&amp;gt;环境变量 –&amp;gt;然后你会看到下面这个界面 -&amp;gt; 点击这个path，然后点编辑 然后找到C:\Python27文件夹，将这个文件夹添加进去。 2.安装djan">
<meta name="twitter:image" content="https://sunchang.oss-cn-beijing.aliyuncs.com/image/828578-20170103195539128-1894247265.png">
  
    <link rel="alternative" href="/atom.xml" title="sunJsona的个人博客" type="application/atom+xml">
  
  
    <link rel="icon" href="http://7xkj1z.com1.z0.glb.clouddn.com/head.jpg">
  
  <link rel="stylesheet" href="/css/style.css">
  
  

  <script src="//cdn.bootcss.com/require.js/2.3.2/require.min.js"></script>
  <script src="//cdn.bootcss.com/jquery/3.1.1/jquery.min.js"></script>

  
</head>
<body>
  <div id="container">
    <div id="particles-js"></div>
    <div class="left-col">
    <div class="overlay"></div>
<div class="intrude-less">
	<header id="header" class="inner">
		<a href="/" class="profilepic">
			
			<img lazy-src="http://7xkj1z.com1.z0.glb.clouddn.com/head.jpg" class="js-avatar">
			
		</a>

		<hgroup>
		  <h1 class="header-author"><a href="/">sunJsona</a></h1>
		</hgroup>

		

		
			<div class="switch-btn">
				<div class="icon">
					<div class="icon-ctn">
						<div class="icon-wrap icon-house" data-idx="0">
							<div class="birdhouse"></div>
							<div class="birdhouse_holes"></div>
						</div>
						<div class="icon-wrap icon-ribbon hide" data-idx="1">
							<div class="ribbon"></div>
						</div>
						
						<div class="icon-wrap icon-link hide" data-idx="2">
							<div class="loopback_l"></div>
							<div class="loopback_r"></div>
						</div>
						
						
					</div>
					
				</div>
				<div class="tips-box hide">
					<div class="tips-arrow"></div>
					<ul class="tips-inner">
						<li>菜单</li>
						<li>标签</li>
						
						<li>友情链接</li>
						
						
					</ul>
				</div>
			</div>
		

		<div class="switch-area">
			<div class="switch-wrap">
				<section class="switch-part switch-part1">
					<nav class="header-menu">
						<ul>
						
							<li><a href="/">主页</a></li>
				        
							<li><a href="/archives">所有文章</a></li>
				        
						</ul>
					</nav>
					<nav class="header-nav">
						<div class="social">
							
						</div>
					</nav>
				</section>
				
				
				<section class="switch-part switch-part2">
					<div class="widget tagcloud" id="js-tagcloud">
						
					</div>
				</section>
				
				
				
				<section class="switch-part switch-part3">
					<div id="js-friends">
					
			          <a target="_blank" class="main-nav-link switch-friends-link" href="https://github.com/smackgg/hexo-theme-smackdown">smackdown</a>
			        
			        </div>
				</section>
				

				
			</div>
		</div>
	</header>				
</div>
    </div>
    <div class="mid-col">
      <nav id="mobile-nav">
  	<div class="overlay">
  		<div class="slider-trigger"></div>
  		<h1 class="header-author js-mobile-header hide">sunJsona</h1>
  	</div>
	<div class="intrude-less">
		<header id="header" class="inner">
			<div class="profilepic">
				<img lazy-src="http://7xkj1z.com1.z0.glb.clouddn.com/head.jpg" class="js-avatar">
			</div>
			<hgroup>
			  <h1 class="header-author">sunJsona</h1>
			</hgroup>
			
			<nav class="header-menu">
				<ul>
				
					<li><a href="/">主页</a></li>
		        
					<li><a href="/archives">所有文章</a></li>
		        
		        <div class="clearfix"></div>
				</ul>
			</nav>
			<nav class="header-nav">
				<div class="social">
					
				</div>
			</nav>
		</header>				
	</div>
</nav>
      <div class="body-wrap"><article id="post-用django创建一个项目" class="article article-type-post" itemscope itemprop="blogPost">
  
    <div class="article-meta">
      <a href="/2020/07/07/用django创建一个项目/" class="article-date">
  	<time datetime="2020-07-07T05:00:13.000Z" itemprop="datePublished">2020-07-07</time>
</a>
    </div>
  
  <div class="article-inner">
    
      <input type="hidden" class="isFancy" />
    
    
      <header class="article-header">
        
  
    <h1 class="article-title" itemprop="name">
      用django创建一个项目
      
    </h1>
  

      </header>
      
      <div class="article-info article-info-post">
        
        

        
        <div class="clearfix"></div>
      </div>
      
    
    <div class="article-entry" itemprop="articleBody">
      
        <p>首先你得安装好python和django，然后配置好环境变量，安装python就不说了，从配置环境变量开始</p>
<h5 id="1-配置环境变量"><a href="#1-配置环境变量" class="headerlink" title="1.配置环境变量"></a>1.配置环境变量</h5><p>在我的电脑处点击右键，或者打开 控制面板\系统和安全\系统 -&gt;</p>
<p>左边导航栏的“高级系统设置”-&gt;环境变量 –&gt;然后你会看到下面这个界面</p>
<p><img src="https://sunchang.oss-cn-beijing.aliyuncs.com/image/828578-20170103195539128-1894247265.png" alt=""><br>-&gt; 点击这个path，然后点编辑</p>
<p>然后找到C:\Python27文件夹，将这个文件夹添加进去。</p>
<h5 id="2-安装django"><a href="#2-安装django" class="headerlink" title="2.安装django"></a>2.安装django</h5><p>打开cmd，执行 pip install django 或者 把<img src="https://sunchang.oss-cn-beijing.aliyuncs.com/image/828578-20170103195951191-1293610516.png" alt=""><br>这个包下载下来，然后解压之后打开，是这样的</p>
<p><img src="https://sunchang.oss-cn-beijing.aliyuncs.com/image/828578-20170103200123878-1846022323.png" alt=""><br>-&gt;打开cmd ,打开这个文件夹,执行 <code>python setup.py install</code><br>等着就行了</p>
<h5 id="3-检验django是否安装成功"><a href="#3-检验django是否安装成功" class="headerlink" title="3. 检验django是否安装成功"></a>3. 检验django是否安装成功</h5><p><code>import django</code><br>如果这句话不报错的话，就没什么问题了。</p>
<h5 id="4-配置django环境变质量。"><a href="#4-配置django环境变质量。" class="headerlink" title="4. 配置django环境变质量。"></a>4. 配置django环境变质量。</h5><p>还是像刚才那样打开环境变量里的path，这次添加的路径是：<img src="https://sunchang.oss-cn-beijing.aliyuncs.com/image/828578-20170103200738237-1012230503.png" alt=""></p>
<ol start="5">
<li>用django创建项目</li>
</ol>
<p>打开cmd，并进入你的工作空间，执行命令：<br><img src="https://sunchang.oss-cn-beijing.aliyuncs.com/image/828578-20170103200951722-394835961.png" alt=""></p>
<p>如果你看到的是下面这样的话，<br><img src="https://sunchang.oss-cn-beijing.aliyuncs.com/image/828578-20170103201030722-218731608.png" alt=""></p>
<p>这可能是版本问题导致的，你可以执行<br><img src="https://sunchang.oss-cn-beijing.aliyuncs.com/image/828578-20170103201118253-933553388.png" alt=""></p>
<p>如果没有任何提示，就是成功了。如果还报错，就得检查检查了。</p>
<p>执行成功之后，在你的工作空间目录会有两层website文件夹，进入到两层website文件夹下，会有以下几个文件</p>
<p><img src="https://sunchang.oss-cn-beijing.aliyuncs.com/image/828578-20170103202329550-1021831256.png" alt=""></p>
<h5 id="6-创建djangoapp"><a href="#6-创建djangoapp" class="headerlink" title="6. 创建djangoapp"></a>6. 创建djangoapp</h5><p>进入website目录下，执行 <code>admin.py startapp blog</code> 或者 <code>admin startapp blog</code><br><img src="https://sunchang.oss-cn-beijing.aliyuncs.com/image/828578-20170103202532987-734281570.png" alt=""></p>
<p>这里还是没有什么提示，这时候在你的website目录下就多了一个blog文件夹，和一个自带的sqlite3数据库。<br><img src="https://sunchang.oss-cn-beijing.aliyuncs.com/image/828578-20170103202638644-219210958.png" alt=""></p>
<h5 id="7-修改-urls-py-和-views-py"><a href="#7-修改-urls-py-和-views-py" class="headerlink" title="7.修改 urls.py 和 views.py"></a>7.修改 urls.py 和 views.py</h5><p>打开 views.py 加入测试代码如下：<br><img src="https://sunchang.oss-cn-beijing.aliyuncs.com/image/828578-20170103203359566-894259538.png" alt=""></p>
<p>其实就是定义了一个函数，然后返回一个字符串。<br>打开 urls.py ，添加一句话<br><code>url(r&#39;^blog/index/$&#39;,blog.views.index,name=&#39;index&#39;)</code></p>
<p><img src="https://sunchang.oss-cn-beijing.aliyuncs.com/image/828578-20170103203233878-325335233.png" alt=""></p>
<h5 id="8-开启服务器"><a href="#8-开启服务器" class="headerlink" title="8. 开启服务器"></a>8. 开启服务器</h5><p>在website目录下运行命令:<br><img src="https://sunchang.oss-cn-beijing.aliyuncs.com/image/828578-20170103203550237-1673257793.png" alt=""></p>
<p>或者 <code>manage.py runserver</code> ，版本不一样导致<br>如果你看到下面这个界面，就代表服务器开启成功了<br><img src="https://sunchang.oss-cn-beijing.aliyuncs.com/image/828578-20170103203725644-2085813319.png" alt=""></p>
<p>你可以打开浏览器，输入 <code>127.0.0.0:8000</code></p>
<p>这个地址，查看结果。</p>

      
    </div>
    
  </div>
  
    
<nav id="article-nav">
  
    <a href="/2020/07/07/深入解析 EventLoop 和浏览器渲染、帧动画、空闲回调的关系/" id="article-nav-newer" class="article-nav-link-wrap">
      <strong class="article-nav-caption">&lt;</strong>
      <div class="article-nav-title">
        
          (no title)
        
      </div>
    </a>
  
  
    <a href="/2020/07/07/微信POST请求接收不到数据问题/" id="article-nav-older" class="article-nav-link-wrap">
      <div class="article-nav-title">微信POST请求接收不到数据问题</div>
      <strong class="article-nav-caption">&gt;</strong>
    </a>
  
</nav>

  
</article>


<div class="ds-share share" data-thread-key="用django创建一个项目" data-title="用django创建一个项目" data-url="https://xiaochangzai.github.io/2020/07/07/用django创建一个项目/"  data-images="http://7xkj1z.com1.z0.glb.clouddn.com/head.jpg" data-content="用django创建一个项目">
    <div class="ds-share-inline">
      <ul  class="ds-share-icons-16">
      	<li data-toggle="ds-share-icons-more"><a class="ds-more" href="javascript:void(0);">分享到：</a></li>
        <li><a class="ds-weibo" href="javascript:void(0);" data-service="weibo">微博</a></li>
        <li><a class="ds-qzone" href="javascript:void(0);" data-service="qzone">QQ空间</a></li>
        <li><a class="ds-qqt" href="javascript:void(0);" data-service="qqt">腾讯微博</a></li>
        <li><a class="ds-wechat" href="javascript:void(0);" data-service="wechat">微信</a></li>
      </ul>
      <div class="ds-share-icons-more">
      </div>
    </div>
 </div>
 





</div>
      <footer id="footer">
  <div class="outer">
    <div id="footer-info">
      <div class="footer-left">
        &copy; 2022 sunJsona
      </div>
        <div class="footer-right">
          <a href="http://hexo.io/" target="_blank">Hexo</a>  Theme <a href="https://github.com/smackgg/hexo-theme-smackdown" target="_blank">Smackdown</a>
        </div>
    </div>
  </div>
</footer>
    </div>
    
  <link rel="stylesheet" href="/fancybox/jquery.fancybox.css">


<script>
	var yiliaConfig = {
		fancybox: true,
		mathjax: true,
		animate: true,
		isHome: false,
		isPost: true,
		isArchive: false,
		isTag: false,
		isCategory: false,
		open_in_new: false
	}
</script>
<script src="/js/main.js"></script>



<script type="text/x-mathjax-config">
MathJax.Hub.Config({
    tex2jax: {
        inlineMath: [ ['$','$'], ["\\(","\\)"]  ],
        processEscapes: true,
        skipTags: ['script', 'noscript', 'style', 'textarea', 'pre', 'code']
    }
});

MathJax.Hub.Queue(function() {
    var all = MathJax.Hub.getAllJax(), i;
    for(i=0; i < all.length; i += 1) {
        all[i].SourceElement().parentNode.className += ' has-jax';                 
    }       
});
</script>

<script src="//cdn.bootcss.com/mathjax/2.7.0/MathJax.js"></script>


  </div>
</body>
</html>